# coding: utf-8


import os
import numpy as np


NORMAL_EXE_PATH = '../software/normal'
MALWARE_EXE_PATH = '../software/malware'
MAX_PROCESS_NUM = 2  # 最大进程数


def analyse_normal_mb():
    files = os.listdir(NORMAL_EXE_PATH)
    file_size_list = []
    counts = [0] * 11
    for file in files:
        exe_file = os.path.join(NORMAL_EXE_PATH, file)
        file_size = os.path.getsize(exe_file)
        file_size = file_size / 1024 / 1024  # 转为 MB
        file_size_list.append(file_size)
        for size_threshold in range(0, 11):
            if file_size > size_threshold:
                counts[size_threshold] += 1
    print('良性软件总数：', len(file_size_list))
    for size_threshold in range(0, 11):
        print('> {} MB 的良性软件数量: {}  {:.2f}%'.format(size_threshold, counts[size_threshold], counts[size_threshold] / len(file_size_list) * 100))


def analyse_normal_kb():
    files = os.listdir(NORMAL_EXE_PATH)
    file_size_list = []
    counts = [0] * 11
    for file in files:
        exe_file = os.path.join(NORMAL_EXE_PATH, file)
        file_size = os.path.getsize(exe_file)
        file_size = file_size / 1024  # 转为 KB
        file_size_list.append(file_size)
        for size_threshold in range(0, 11):
            if file_size > size_threshold:
                counts[size_threshold] += 1
    print('良性软件总数：', len(file_size_list))
    for size_threshold in range(0, 11):
        print('> {} KB 的良性软件数量: {}  {:.2f}%'.format(size_threshold, counts[size_threshold], counts[size_threshold] / len(file_size_list) * 100))


def analyse_malware_mb():
    files = os.listdir(MALWARE_EXE_PATH)
    file_size_list = []
    counts = [0] * 11
    for file in files:
        exe_file = os.path.join(MALWARE_EXE_PATH, file)
        file_size = os.path.getsize(exe_file)
        file_size = file_size / 1024 / 1024  # 转为 MB
        file_size_list.append(file_size)
        for size_threshold in range(0, 11):
            if file_size > size_threshold:
                counts[size_threshold] += 1
    print('恶意软件总数：', len(file_size_list))
    for size_threshold in range(0, 11):
        print('> {} MB 的恶意软件数量: {}  {:.2f}%'.format(size_threshold, counts[size_threshold], counts[size_threshold] / len(file_size_list) * 100))


def analyse_malware_kb():
    files = os.listdir(MALWARE_EXE_PATH)
    file_size_list = []
    counts = [0] * 11
    for file in files:
        exe_file = os.path.join(MALWARE_EXE_PATH, file)
        file_size = os.path.getsize(exe_file)
        file_size = file_size / 1024  # 转为 KB
        file_size_list.append(file_size)
        for size_threshold in range(0, 11):
            if file_size > size_threshold:
                counts[size_threshold] += 1
    print('恶意软件总数：', len(file_size_list))
    for size_threshold in range(0, 11):
        print('> {} KB 的恶意软件数量: {}  {:.2f}%'.format(size_threshold, counts[size_threshold], counts[size_threshold] / len(file_size_list) * 100))


def analyse_malware_b():
    files = os.listdir(MALWARE_EXE_PATH)
    file_size_list = []
    counts = [0] * 11
    for file in files:
        exe_file = os.path.join(MALWARE_EXE_PATH, file)
        file_size = os.path.getsize(exe_file)
        file_size = file_size  # 转为 B
        file_size_list.append(file_size)
        for size_threshold in range(0, 11):
            if file_size > size_threshold * 100:
                counts[size_threshold] += 1
    print('恶意软件总数：', len(file_size_list))
    for size_threshold in range(0, 11):
        print('> {} B 的恶意软件数量: {}  {:.2f}%'.format(size_threshold * 100, counts[size_threshold], counts[size_threshold] / len(file_size_list) * 100))


if __name__ == '__main__':
    print('=' * 100)
    analyse_normal_mb()
    print('=' * 100)
    analyse_malware_mb()
    print('=' * 100)
    analyse_normal_kb()
    print('=' * 100)
    analyse_malware_kb()
    print('=' * 100)
    analyse_malware_b()
    